package edu.whu.puppygo.service.Impl;

import com.alibaba.fastjson.JSON;
import edu.whu.puppygo.config.RabbitmqConfig;
import edu.whu.puppygo.dto.VqaDto;
import edu.whu.puppygo.service.VqaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author xinjiezhuang
 * @Date 2023-11-14
 */
@Service
@Slf4j
public class VqaServiceImpl implements VqaService {
    @Resource
    RabbitTemplate rabbitTemplate;

    @Override
    public boolean sendMsg(String image, String text, Long fragmentId) {
        log.info("vqa : sendMsg");
        VqaDto vqa = new VqaDto();
        vqa.setImage(image);
        vqa.setText(text);
        vqa.setFragmentId(fragmentId);
        log.info("vqa : {}", vqa);
        String jsonBody = JSON.toJSONString(vqa);
        log.info("jsonBody : {}", jsonBody);
        rabbitTemplate.convertAndSend(RabbitmqConfig.DIRECT_EXCHANGE, "vqa", jsonBody);

        return true;
    }
}
